package spring.cloud.canary.demo.controller;

import jk.framework.canary.core.CanaryMgt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import spring.cloud.canary.demo.remote.CanaryRemoteService;
import spring.cloud.canary.demo.remote.ProviderRemoteService;

import javax.servlet.http.HttpServletRequest;

/**
 * @author cuichao
 */
@RestController
@RequestMapping("consumer")
public class ConsumerController {

    @Autowired
    private ProviderRemoteService remoteService;

    @Autowired
    private CanaryRemoteService canaryRemoteService;

    @GetMapping("ping")
    public String consumer(HttpServletRequest request){
        String abc = request.getHeader("abc");
        System.out.println(abc);
        return remoteService.ping();
    }

    @GetMapping("canary")
    public String canary(){
        String localVer = CanaryMgt.getController().localCurrentVersion().getVersion();

        String providerVer = canaryRemoteService.canary();

        return "consumer版本号为: "+localVer+" provider版本号为: "+providerVer;
    }

}
